package com.monas.server;

import java.util.LinkedList;
import java.util.List;

import com.monas.server.database.MonasDatabase;

/**
 * Class untuk mendapatkan nilai konfigurasi dari system, file, maupun database.
 * 
 * @since 8 Juli 2012
 * @author ekowahyudi
 * 
 */
public class MonasProperties {

	public static String getSystemProperty(String key) {
		return System.getProperty(key);
	}

	public static String getDBProperty(String key) {
		MonasDatabase database = MonasDatabase.getInstance();

		String query = "SELECT value FROM tb_properties WHERE key = '" + key
				+ "'";
		return database.getProperty(query);
	}

	public static String getDBProperty(String node, String key) {
		MonasDatabase database = MonasDatabase.getInstance();

		String query = "SELECT value FROM tb_node WHERE node = '" + node
				+ "' AND key = '" + key + "'";
		return database.getProperty(query);
	}

	public static List<String> getAllServer() {
		MonasDatabase database = MonasDatabase.getInstance();
		LinkedList<String> servers = new LinkedList<String>();

		String query = "SELECT DISTINCT node FROM tb_node ORDER BY node";

		for (Object[] fields : database.executeQuery(query)) {
			servers.add((String) fields[0]);
		}
		return servers;
	}

}
